home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / sharewar / FFE / SOUND.SWG / 0040_PATCH for GUS.pas < prev    next >
Pascal/Delphi Source File  |  1997-05-11  |  8KB  |  132 lines

  1. {                     ** FORTE's patch format, v1.10 **                      }
  2. {   (compiled from various sources, most notably Francois Dion's PATCHKIT)   }
  3.  
  4.  
  5.  
  6. {  Patch file structure:
  7.  
  8. ┌───────────────────────────────┐
  9. │  PatchHeader                  │
  10. ├───────────────────────────────┤
  11. │  instruments *                │
  12. │  ┌────────────────────────────┴──┐
  13. │  │  InstrumentHeader             │
  14. │  ├───────────────────────────────┤
  15. │  │  layers *                     │
  16. │  │  ┌────────────────────────────┴──┐
  17. │  │  │  LayerHeader                  │
  18. │  │  ├───────────────────────────────┤
  19. │  │  │  samples *                    │
  20. │  │  │  ┌────────────────────────────┴──┐
  21. └──┤  │  │  WaveHeader                   │
  22.    └──┤  ├───────────────────────────────┤
  23.       └──┤  The actual sample data       │
  24.          └───────────────────────────────┘ }
  25.  
  26.  
  27. type
  28.   PatchHeader = record
  29.     header        : array[0..11] of Char; { asciz, Currently 'GF1PATCH110'#0  }
  30.     gravis_id     : array[0..9] of Char;  { asciz, Always 'ID#000002'         }
  31.     description   : array[0..59] of Char; { asciz, Whatever you want, (Gravis }
  32.                                           { uses it for a copyright notice)   }
  33.     instruments   : Byte;                 { 1, number of instruments in patch }
  34.                                           { Could be > 1 but why such a thing?}
  35.     voices        : Byte;                 { 14, Playback voices, ignored      }
  36.     channels      : Byte;                 { 0, ignored, Wav channels that can }
  37.                                           { be played beside the patch        }
  38.     waveforms     : Word;                 { Total number of waveforms in file }
  39.     master_volume : Word;                 { Master Volume, 00..7F             }
  40.     data_size     : DWord;                { Memory patch takes in gusram?     }
  41.     reserved      : array[0..35] of Byte; { For future extensions }
  42.   end;
  43.  
  44.   InstrumentHeader : record
  45.     instrument_id  : Word;                { Instrument id: 0..FFFF            }
  46.     instrument_name: array[0..15] of Char;{ Name of instrument                }
  47.                                           { Not used in patches of 2.06 disks }
  48.                                           { but you SHOULD use it, This is    }
  49.                                           { what's seen when you choose  'Use }
  50.                                           { Names from Patch files' in the Win}
  51.                                           { Patch Manager, and it will become }
  52.                                           { essential once we have bank-switch}
  53.                                           { and not only GM-sounds            }
  54.     instrument_size: DWord;               { Number of bytes for the instrument}
  55.                                           { incl. header.To skip to next instr}
  56.     layers         : Byte;                { 1, Number of layers in instr: 1-4 }
  57.                                           { Current drivers only support 1    }
  58.     reserved       : array[0..39] of Byte;{ For future extensions             }
  59.   end;
  60.  
  61.   LayerHeader = record
  62.     layer_dup : Byte;             { If not 0 the wavesample to use is from the }
  63.                    { previous layer. Waveheader is still needed }
  64.     layer_id  : Byte;             { 0, Layer id: 0..3                          }
  65.     layer_size: DWord;            { Data size in bytes in the layer, excluding }
  66.                                   { the header. To skip to next layer          }
  67.     samples   : Byte;             { number of wavesamples                      }
  68.     reserved  : array[0..39] of Byte; { For future extensions                  }
  69.   end;
  70.  
  71.   WaveHeader = record
  72.     wave_name : array[0..6] of Char; { asciz. name of the wave. 'NoName'#0 if }
  73.                                      { none, use 'C3', 'High' and such names  }
  74.     fractions      : Byte;        { Start loop point fraction in 4 bits + End }
  75.                                   { loop point fraction in the 4 other bits;  }
  76.                   { used when looppoint is between two samples}
  77.     wave_size      : DWord;       { Total size of wavesample. Limited to 64KB }
  78.                                   { now by the drivers,card can do up to 256KB}
  79.     start_loop     : DWord;       { Start loop position                       }
  80.     end_loop       : DWord;       { End loop position                         }
  81.     sample_rate    : Word;        { Sample frequency, in Hz                   }
  82.     low_frequency  : DWord;       { Lowest frequency to play, see scale_table }
  83.     high_frequency : DWord;       { Highest frequency to play, see scale_table}
  84.     root_frequency : DWord;       { Root frequency to play, see scale_table   }
  85.                                   { The 'frequency' wich correspond to the    }
  86.                                   { sample_rate.(this is the freq that sounds }
  87.                                   { in the drum bank are played at)           }
  88.     tune           : Integer;     { Always 1, not used anymore                }
  89.     balance        : Byte;        { Pan, 0..15, (0-full left, 15-full right)  }
  90.     envelope_rate  : array[0..5] of Byte; { attack rates                      }
  91.     envelope_offset: array[0..5] of Byte; { attack offsets                    }
  92.     { I have not been able to fully understand the envelope bytes:            }
  93.     { The rates are the rate of amplitude change (I think the alowed range is }
  94.     { 1..3F for point 1-5 and 1..CF for point 6 or something...) wich goes on }
  95.     { until the corresponding 'offset' (what time unit?) is reached (maybe its}
  96.     { somekind of dy/dx desciption).    Different parts of the  envelope  are }
  97.     { enabled/disabled via the mode byte below.You should try Gravis PATCH.EXE}
  98.     { (from the SDK) or another patch editor to fiddle around with it a little}
  99.     tremolo_sweep  : Byte;          { tremolo sweep (sensitivity? amplitude?) }
  100.     tremolo_rate   : Byte;          { tremolo rate  }
  101.     tremolo_depth  : Byte;          { tremolo depth }
  102.     vibrato_sweep  : Byte;          { vibrato sweep  }
  103.     vibrato_rate   : Byte;          { vibrato rate (lfo - sine) }
  104.     vibrato_depth  : Byte;          { vibrato depth }
  105.     modes          : Byte;          { A set of flags: }
  106.     { bit 0 = 0=8 bit, 1=16 bit wave data.                                    }
  107.     { bit 1 = 0=Signed data, 1=Unsigned data.                                 }
  108.     { bit 2 = 1=Enable looping                                                }
  109.     { bit 3 = 1=Enable bidirectional looping                                  }
  110.     { bit 4 = 1=Enable looping backward                                       }
  111.     { bit 5 = 1=Enable sustain (3rd point of envelope)                        }
  112.     { bit 6 = 1=Enable envelopes, must be set if you want to hear anything    }
  113.     { bit 7 = 1=Enable clamped release (6th point of envelope) }
  114.     scale_frequency: Integer;       { 60, Dunno what it is }
  115.     scale_factor   : Word;          { from 0 to 2048, 1024 is normal          }
  116.                                     { freq := (freq*scale_factor) shr 10 }
  117.     reserved: array[0..35] of Byte; { For future extensions }
  118.   end;
  119.  
  120.  
  121. const
  122.   scale_table : array[0..107] of DWord = (  {C-0..B-8}
  123.   { Octave 0 }  16351, 17323, 18354, 19445, 20601, 21826, 23124, 24499, 25956, 27500, 29135, 30867,
  124.   { Octave 1 }  32703, 34647, 36708, 38890, 41203, 43653, 46249, 48999, 51913, 54999, 58270, 61735,
  125.   { Octave 2 }  65406, 69295, 73416, 77781, 82406, 87306, 92498, 97998, 103826, 109999, 116540, 123470,
  126.   { Octave 3 }  130812, 138591, 146832, 155563, 164813, 174614, 184997, 195997, 207652, 219999, 233081, 246941,
  127.   { Octave 4 }  261625, 277182, 293664, 311126, 329627, 349228, 369994, 391995, 415304, 440000, 466163, 493883,
  128.   { Octave 5 }  523251, 554365, 587329, 622254, 659255, 698456, 739989, 783991, 830609, 880000, 932328, 987767,
  129.   { Octave 6 }  1046503, 1108731, 1174660, 1244509, 1318511, 1396914, 1479979, 1567983, 1661220, 1760002, 1864657, 1975536,
  130.   { Octave 7 }  2093007, 2217464, 2349321, 2489019, 2637024, 2793830, 2959960, 3135968, 3322443, 3520006, 3729316, 3951073,
  131.   { Octave 8 }  4186073, 4434930, 4698645, 4978041, 5274051, 5587663, 5919922, 6271939, 6644889, 7040015, 7458636, 7902150 );
  132.